package com.good.child.ui.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.good.child.R;
import com.good.child.iview.LoginIView;
import com.good.child.pressent.LoginPresenter;
import com.good.child.widgets.editext.ClearEditText;
import com.yimidida.library.base.BaseActivity;
import com.yimidida.library.utils.ToastUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Create on: 2024/6/11
 * by Mr.Zhu
 * Description: TODO
 */
public class CalculatorActivity extends BaseActivity<LoginIView, LoginPresenter> implements LoginIView  {


    @BindView(R.id.shop_bei_chu)
    ClearEditText beiClearEditText;
    @BindView(R.id.shop_chushu)
    ClearEditText chuClearEditText;
    @BindView(R.id.forget_jieguo_tv)
    TextView resultTV;
    @BindView(R.id.submit_btn_jisuan)
    Button jisuanBtn;
    @BindView(R.id.submit_btn_clear)
    Button clearBtn;



    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_calculator);
        ButterKnife.bind(this);
        initView();
    }


    @Override
    protected LoginPresenter initPresenter() {
        return new LoginPresenter(this);
    }

    @Override
    protected void initView() {
        jisuanBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String beichushu = beiClearEditText.getText().toString();
                String chushu = chuClearEditText.getText().toString();
                if (TextUtils.isEmpty(beichushu) || TextUtils.isEmpty(chushu)) {
                    return;
                }
                int dividend = Integer.valueOf(beichushu);
                int divisor = Integer.valueOf(chushu);
                if (dividend < divisor) {
                    ToastUtil.showShort("被除数不能小于除数");
                    return;
                }
                int quotient = dividend / divisor; // 获取商
                int remainder = dividend % divisor;  // 获取余数
                resultTV.setText("商为=" + quotient + "    余数为=" + remainder);

            }
        });

        clearBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                beiClearEditText.setText("");
                chuClearEditText.setText("");
                resultTV.setText("");
            }
        });

    }

    @Override
    public void onUserLoginSuccess() {

    }
}
